import pygame.font

class GameOverButton:
    def __init__(self, ai_game, msg):
        self.screen = ai_game.screen
        self.screen_rect = self.screen.get_rect()
        self.width, self.height = 400, 100
        # 红色
        self.gameOver_button_color = (255,0,0)
        # 黑色内容
        self.gameOver_text_color = (0, 0, 0)
        # 创建字体对象
        self.gameOver_font = pygame.font.SysFont(None, 60)
        # 位置
        self.gameOver_rect = pygame.Rect(0, 0, self.width, self.height)
        self.gameOver_rect.center = self.screen_rect.center
        self._prep_msg(msg)

    # msg渲染成图像，并将其在按钮上居中
    def _prep_msg(self, msg):
        self.msg_image = self.gameOver_font.render(msg, True, self.gameOver_text_color, self.gameOver_button_color)
        self.msg_image_rect = self.msg_image.get_rect()
        self.msg_image_rect.center = self.gameOver_rect.center
    
    # 绘制出红色按钮，将文字绘制到按钮中间
    def draw_button(self):
        self.screen.fill(self.gameOver_button_color, self.gameOver_rect)
        self.screen.blit(self.msg_image, self.msg_image_rect)
    
